<?php
class masterbarangdetail_model extends CI_Model{
	private $KodeBarang;
    private $KodeDetailBarang;
    private $Productname;
    private $Typeunit;
  	private $Description;
	private $Itemprice;
    private $CreatedBy;
    private $CreatedOn;
    private $LastUpdateBy;
  	private $LastUpdateOn;
  	private $Active;
	
	function setKodeBarang($KodeBarang){
		$this->KodeBarang = $KodeBarang;
	}
	function getKodeBarang(){
		return $this->KodeBarang;
	}
	
	function setKodeDetailBarang($kddetbarang){
		$this->KodeDetailBarang = $kddetbarang;
	}
	function getKodeDetailBarang(){
		return $this->KodeDetailBarang;
	}
	
	function setProductname($Productname){
		$this->Productname = $Productname;
	}
	function getProductname(){
		return $this->Productname;
	}
	
	function setTypeunit($Typeunit){
		$this->Typeunit = $Typeunit;
	}
	function getTypeunit(){
		return $this->Typeunit;
	}
	
	function setDescription($Description){
		$this->Description = $Description;
	}
	function getDescription(){
		return $this->Description;
	}
	
	function setItemprice($itmprice){
		$this->Itemprice = $itmprice;
	}
	function getItemprice(){
		return $this->Itemprice;
	}
	
	function setCreatedBy($c_by){
		$this->CreatedBy = $c_by;
	}
	function getCreatedBy(){
		return $this->CreatedBy;
	}

	function setCreatedOn($dateNow){
		//$dateNow = date('Y-m-d H:i:s');
		$this->CreatedOn = $dateNow;
	}
	function getCreatedOn(){
		return $this->CreatedOn;
	}

	function setLastUpdateBy($u_by){
		$this->LastUpdateBy = $u_by;
	}
	function getLastUpdateBy(){
		return $this->LastUpdateBy;
	}

	function setLastUpdateOn($dateNow){
		//$dateNow = date('Y-m-d H:i:s');
		$this->LastUpdateOn = $dateNow;
	}
	function getLastUpdateOn(){
		return $this->LastUpdateOn;
	}

	function setActive($active_val){
		$this->Active = $active_val;
	}
	function getActive(){
		return $this->Active;
	}
	
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function insert(){
		
		$data = array(
			'KodeBarang' => $this->getKodeBarang(),
			'KodeDetailBarang' => $this->getKodeDetailBarang(),
			'Productname' => $this->getProductname(),
			'Typeunit' => $this->getTypeunit(),
			'Description' => $this->getDescription(),
			'Itemprice' => $this->getItemprice(),
			'Createdby' => $this->getCreatedBy(),
			'Createdon' => $this->getCreatedOn(),
			'Lastupdateby' => $this->getLastupdateby(),
			'Lastupdateon' => $this->getLastupdateon(),
			'Active' => '1'					
		);
		
		$this->db->insert('detail_product',$data);
	}
	
	function ubahdetailbarang() 
	{
            $data = array(
                'Productname' => $this->getProductname(),
                'Typeunit' => $this->getTypeunit(),
                'Description' => $this->getDescription(),
				'Itemprice' => $this->getItemprice(),
                'Lastupdateby' => $this->getLastupdateby(),
				'Lastupdateon' => $this->getLastupdateon(),
            );
 
        $this->db->where(array('KodeDetailBarang' => $this->getKodeDetailBarang()));
        $this->db->update('detail_product', $data);
		//var_dump($this->db->last_query());exit;
    }

    function deletedetailbarang() {
        $data = array(
            'active' => '0'
        );
        $this->db->where(array('KodeDetailBarang' => $this->getKodeDetailBarang()));
        $this->db->update('detail_product', $data);
    }
	
	function getall(){
		$this->db->select()->where(array('Active'=>'1'));
		$query = $this->db->get('detail_product');
		return $query->result();
	}
	
	function getList($idkddet){
		$this->db->select()->where(array('KodeBarang' => $idkddet,'Active'=>'1'));
		$query = $this->db->get('detail_product');
		return $query->result();
	}
	
	function getBarangByKode()
	{
		$this->db->select()->where(array('KodeDetailBarang' => $this->getKodeDetailBarang(),'Active'=>'1'));
		$query = $this->db->get('detail_product');
		return $query->result();
	}
	
	function getBarang($idkddet)
	{
		$this->db->select("product_header.KodeBarang")->where(array('KodeBarang' => $idkddet,'active'=>'1'));
		$query = $this->db->get('product_header');
		return $query->result();
	}
	
	function getkdbaranglike(){
		$this->db->select()
		->where(array('Active'=>'1'))->like(array('KodeDetailBarang' => $this->getKodeDetailBarang()));
		$query = $this->db->get('detail_product');
		return $query->result();
	}
	
	function getnamabaranglike(){
		$this->db->select()
		->where(array('Active'=>'1'))->like(array('Productname' => $this->getProductname()));
		$query = $this->db->get('detail_product');
		return $query->result();
	}
	
}